﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace CSharpDemo._02_对象和类型
{
    class Person
    {
        private int age;
        private string name;

        //只读字段(只能在构造函数中赋值)
        public readonly DateTime CreateTime;


        public static void Test()
        {
            Console.WriteLine("\n属性测试");
            Person jack = new Person();
            Console.WriteLine("name:" + jack.Name + "\nage:" + jack.Age + "\nid:" + jack.Id);
        }

        public Person()
        {
            this.age = 1;
            this.name = "jack";
            CreateTime = new DateTime(2014, 5, 17);
        }


        //1.属性封装私有变量
        public int Age
        {
            get
            {
                return age;
            }
            set
            {
                age = value;
            }
        }

        //2.只读属性
        public string Name
        {
            get
            {
                return name;
            }
        }

        //3. 自动实现的属性
        public int Id { get; set; }
    }
}
